unit Rptbs;

interface

uses
  Windows, DB, ADODB, frxClass, frxDBSet, frxExportPDF, frxExportXML,
  frxExportXLS, frxExportHTML, frxExportTXT, frxExportRTF, frxExportImage,
  frxBarcode, frxBDEComponents, frxCross, frxDMPExport, frxOLE, frxDCtrl,
  frxChart, frxRich, frxDesgn, frxGZip, RzButton, ComCtrls, Controls,
  StdCtrls, Buttons, ExtCtrls, Classes, frxPreview, Forms, SysUtils, StrUtils;

type

  TRptbsfrm = class(TForm)
    rptview: TfrxPreview;
    pal_ctrl: TPanel;
    btnClose: TSpeedButton;
    labcaption: TLabel;
    palMenu: TPanel;
    comboRFID: TComboBox;
    strdtpicker: TDateTimePicker;
    enddtpicker: TDateTimePicker;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    RzBitBtn1: TRzBitBtn;
    RzBitBtn2: TRzBitBtn;
    RzBitBtn3: TRzBitBtn;
    frxGZipCompressor1: TfrxGZipCompressor;
    frxDesigner1: TfrxDesigner;
    frxRichObject1: TfrxRichObject;
    frxChartObject1: TfrxChartObject;
    frxDialogControls1: TfrxDialogControls;
    frxOLEObject1: TfrxOLEObject;
    frxDotMatrixExport1: TfrxDotMatrixExport;
    frxCrossObject1: TfrxCrossObject;
    frxBDEComponents1: TfrxBDEComponents;
    frxBarCodeObject1: TfrxBarCodeObject;
    frxBMPExport1: TfrxBMPExport;
    frxJPEGExport1: TfrxJPEGExport;
    frxTIFFExport1: TfrxTIFFExport;
    frxRTFExport1: TfrxRTFExport;
    frxTXTExport1: TfrxTXTExport;
    frxHTMLExport1: TfrxHTMLExport;
    frxXLSExport1: TfrxXLSExport;
    frxXMLExport1: TfrxXMLExport;
    frxPDFExport1: TfrxPDFExport;
    rptdbSource: TDataSource;
    RptDS: TfrxDBDataset;
    dbRpt: TADOQuery;
    dbpicker: TADOQuery;
    pickerdbSource: TDataSource;
    pickerDS: TfrxDBDataset;
    dbcontractor: TADOQuery;
    constractordbsource: TDataSource;
    contractorDS: TfrxDBDataset;
    dbproduct: TADOQuery;
    productdbsource: TDataSource;
    productDS: TfrxDBDataset;
    dbother: TADOQuery;
    otherdbSource: TDataSource;
    otherDS: TfrxDBDataset;
    sptBtn: TRzBitBtn;
    frxReport: TfrxReport;
    procedure pal_ctrlResize(Sender: TObject);
    procedure btnCloseClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure palMenuResize(Sender: TObject);
    procedure strdtpickerChange(Sender: TObject);
    procedure enddtpickerChange(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure comboRFIDChange(Sender: TObject);
    procedure sptBtnClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormMouseWheel(Sender: TObject; Shift: TShiftState;
      WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure frmexit;virtual;abstract;
  end;

var
  Rptbsfrm: TRptbsfrm;

implementation

{$R *.dfm}   

uses
  includefile, dbmodule, editpicker;

procedure TRptbsfrm.pal_ctrlResize(Sender: TObject);
begin
  btnClose.Left:=pal_ctrl.Width-btnClose.Width-3;
end;

procedure TRptbsfrm.btnCloseClick(Sender: TObject);
begin
  frmexit;
end;

procedure TRptbsfrm.FormCreate(Sender: TObject);
begin
  strdtpicker.DateTime:=now;
  enddtpicker.DateTime:=now;
end;

procedure TRptbsfrm.palMenuResize(Sender: TObject);
begin
  RzBitBtn1.Left:=palMenu.Width-3*RzBitBtn1.Width-4;
  RzBitBtn2.Left:=palMenu.Width-2*RzBitBtn2.Width-3;
  RzBitBtn3.Left:=palMenu.Width-1*RzBitBtn3.Width-2;
end;

procedure TRptbsfrm.strdtpickerChange(Sender: TObject);
begin
  if strdtpicker.DateTime>enddtpicker.DateTime then
    enddtpicker.DateTime:=strdtpicker.DateTime;
end;

procedure TRptbsfrm.enddtpickerChange(Sender: TObject);
begin
  if strdtpicker.DateTime>enddtpicker.DateTime then
    strdtpicker.DateTime:=enddtpicker.DateTime;
end;

procedure TRptbsfrm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  dbRpt.Active:=False;  
end;

procedure TRptbsfrm.comboRFIDChange(Sender: TObject);
begin
  if (0=comboRFID.ItemIndex) then
    sptBtn.Enabled:=False
  else
    sptBtn.Enabled:=True;

end;

procedure TRptbsfrm.sptBtnClick(Sender: TObject);
var
  rfid:String;
  tmpPicker:TPicker;
  index:integer;
begin
  rfid:=Trim(LeftStr(comboRFID.Text,10));
  index:=comboRFID.ItemIndex;
  With Teditpickerfrm.Create(Application) do begin
    Caption:=GetCaption('editpickerfrm',999);
    tmpPicker:=dbModulefrm.getPicker(rfid);
    txtRFID.Text:=rfid;
    txtName.Text:=tmpPicker.name;
    dtpbthday.DateTime:=tmpPicker.birthday;
    txtLKMan.Text:=tmpPicker.ID_DOC;
    txtLKManTEL.Text:=tmpPicker.MOB_TEL;
    txtTFN.Text:=tmpPicker.TFN;
    txtaddress.Text:=tmpPicker.address;
    txtEmail.Text:=tmpPicker.Email;
    txtHM_TEL.Text:=tmpPicker.HM_TEL;
    txtExt.Text:=tmpPicker.Ext; 
    if Trim(tmpPicker.sex)='FEMALE' then
      cmbxSex.ItemIndex:=1
    else
      cmbxSex.ItemIndex:=0;

    case tmpPicker.TFNtype of
      0:cmbxTFNTYPE.ItemIndex:=0;
      1:cmbxTFNTYPE.ItemIndex:=1;
      else cmbxTFNTYPE.ItemIndex:=2;
    end;
    cmbxcontractor.Text:=dbmodulefrm.getConstractorNameByID(tmpPicker.contractor);    
    if MroK=showmodal then begin
      dbmodulefrm.dbquery.Active:=False;
      dbmodulefrm.dbquery.SQL.Clear;
      dbmodulefrm.dbquery.SQL.Add('Update employee ');
      dbmodulefrm.dbquery.sql.Add(Format('SET RFID=''%s'', [NAME]=''%s'', SEX=''%s'', BIRTHDAY=#%s#,',
                [RightStr('0000000000'+txtRFID.Text,10),txtNAME.text,cmbxSex.Text,FormatDateTime('yyyy-MM-dd',dtpBthday.Date)]));
      dbmodulefrm.dbquery.sql.Add(Format('TFN=''%s'', TFNTYPE=%d, CONTRACTORNAME=%d, ID_DOC=''%s'',',
                                          [txtTFN.text,cmbxTfntype.itemindex,strtoint(Trim(LeftStr(cmbxcontractor.text,4))),txtLKman.text]));
      dbmodulefrm.dbquery.sql.Add(Format('MOB_TEL=''%s'', ADDRESS=''%s'', EMAIL=''%s'',EXT=''%s'',HM_TEL=''%s''',
                                          [txtLkmantel.text,txtaddress.text,txtemail.text,txtext.text,txthm_tel.text]));
      dbmodulefrm.dbquery.sql.Add(Format('Where Right(RFID,%d)=''%s''',[RFIDLEN,RFID]));
      dbmodulefrm.dbquery.ExecSQL;
    end;
  end;
  dbmodulefrm.getRFIDName(comboRFID.Items);
  comboRFID.Items.Insert(0,'All');
  comboRFID.ItemIndex:=index;
end;

procedure TRptbsfrm.FormShow(Sender: TObject);
begin
  dbmodulefrm.getRFIDName(comboRFID.Items);
  comboRFID.Items.Insert(0,'All');
  comboRFID.ItemIndex :=0;
  strdtpicker.Format:=DateFrtStr;
  enddtpicker.Format:=DateFrtStr;
end;

procedure TRptbsfrm.FormMouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
begin
  rptview.MouseWheelScroll(WheelDelta);
end;

end.
